export default {
  getCates({ commit, state }) {
    return new Promise((resolve, reject) => {
      const cates = [
        { icon: 'rest', name: 'PHP', link: '/blog/cate/php' },
        { icon: 'fire', name: 'Python', link: '/blog/cate/python' },
        { icon: 'trophy', name: 'Javascript', link: '/blog/cate/js' },
      ]
      commit('SET_CATES', cates)
      resolve()
    })
  },
  getArticles({ commit, state }) {
    return new Promise((resolve, reject) => {
      const articles = [
        {
          id: 1,
          author: 'Dapianzi Carl',
          title: '月染长安',
          summary: '高丽太子，大唐，幻镜',
          rate: 9.0,
        },
        {
          id: 2,
          author: 'Dapianzi Carl',
          title: '辛尼兰',
          summary: '腹黑白雪公主与野心家国王',
          like: 5,
          rate: 8.5,
        },
        {
          id: 3,
          author: 'Dapianzi Carl',
          title: '古木吟',
          summary: '善良少年轮回梦境拯救国殇',
          like: 5,
          rate: 9.2,
        },
        {
          id: 4,
          author: 'Dapianzi Carl',
          title: '年轮',
          summary: '此生无可恋',
          like: 5,
          rate: 9.8,
        },
        {
          id: 5,
          author: 'Dapianzi Carl',
          title: '雾蜃岛',
          summary: '保守派or保留最后的人性',
          like: 5,
          rate: 8.6,
        },
        {
          id: 6,
          author: 'Dapianzi Carl',
          title: '二重身之荣格线',
          summary: '作者一个人的狂欢',
          like: 5,
          rate: 7.1,
        },
      ]
      setTimeout(() => {
        commit('SET_ARTICLES', articles)
        resolve()
      }, 800)
    })
  },
  getComments({ commit, state }, id) {
    return new Promise((resolve, reject) => {
      const comments = [
        {
          user: {
            id: 15,
            name: 'Carl',
          },
          content: 'Full of bullshit',
          stamp: '2020-08-24 18:13:59',
          votes: [{ type: 'like', num: 9 }],
        },
        {
          user: {
            id: 14,
            name: 'Bot',
          },
          content: "It's clear and helpful to learn how to use Nuxt",
          stamp: '2020-08-24 18:16:35',
          votes: [
            { type: 'like', num: 2 },
            { type: 'dislike', num: 1 },
          ],
        },
      ]
      setTimeout(() => {
        commit('SET_COMMENTS', comments)
        resolve()
      })
    })
  },
  addComment({ commit, state }, data) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        commit('ADD_COMMENT', data)
        resolve()
      }, 500)
    })
  },
}
